<template>
  <teleport to="body">
    <div v-if="show" class="custom-popup-overlay" @click="closeOnOverlayClick && onClose">
      <div class="custom-popup-container" @click.stop>
        <div class="custom-popup-header">
          <div class="custom-popup-title">{{ title }}</div>
          <van-icon name="cross" @click="onClose" class="custom-popup-close"/>
        </div>
        <div class="custom-popup-content">
          <slot></slot>
        </div>
        <div class="custom-popup-footer">
          <slot name="footer">
            <van-button type="primary" block @click="onClose">关闭</van-button>
          </slot>
        </div>
      </div>
    </div>
  </teleport>
</template>

<script>
import { Icon, Button } from 'vant';

export default {
  name: 'CustomPopup',
  components: {
    vanIcon: Icon,
    vanButton: Button
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '标题'
    },
    closeOnOverlayClick: {
      type: Boolean,
      default: true
    }
  },
  emits: ['update:show', 'close'],
  setup(props, { emit }) {
    const onClose = () => {
      emit('update:show', false);
      emit('close');
    };

    return {
      onClose
    };
  }
};
</script>

<style scoped>
.custom-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.custom-popup-container {
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  background-color: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: popup-fade-in 0.3s;
}

@keyframes popup-fade-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.custom-popup-header {
  padding: 16px;
  border-bottom: 1px solid #ebedf0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custom-popup-title {
  font-size: 16px;
  font-weight: 500;
  color: #323233;
}

.custom-popup-close {
  padding: 4px;
  cursor: pointer;
}

.custom-popup-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.custom-popup-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid #ebedf0;
}
</style> 